<extend name="common:commonNewerTemplate" />
<block name="main_content">
<style type="text/css">
.table th {
    padding: 5px 0px 2px !important;
}
</style>
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a class="tip-bottom" href="index.html" data-original-title="Go to Home">
				<i class="icon-home"></i> 首页
			</a>
			<a href="#">大客户订单</a> 
			<a class="current" href="#">经销商发票开具</a>
		</div>
	</div>
	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"> <i class="icon-info-sign"></i></span>
						<h5>搜索条件</h5>
					</div>
					<div class="widget-content nopadding">
						<form novalidate="novalidate" id="basic_validate" name="basic_validate" action="#" method="post" class="form-horizontal">
							<div class="control-group">
								<label class="control-label">订单编号</label>
								<div class="controls">
									<input type="text" id="order_id" name="order_id">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">经销商姓名</label>
								<div class="controls">
									<input type="text" id="dealer_name" name="dealer_name">
								</div>
							</div>
						
							<div class="control-group">
								<label class="control-label">经销商类型：</label>
								<div class="controls">
								<select id="dealer_type" name="dealer_type" style="width:220px;" >
									<option value="">--请选择--</option>
									<option value="1">一般纳税人</option>
									<option value="2">个体工商户</option>
								</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">发货日期：</label>
								<div class="controls">
									<input id="start_date" name="start_date" style="background-color: #fff;border: 1px solid #ccc;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;width:217px;color:#555;transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">&nbsp;-
									<input id="end_date" name="end_date" style="background-color: #fff;border: 1px solid #ccc;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;width:217px;color:#555;transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">订单日期：</label>
								<div class="controls">
									<input id="start_o_date" name="start_o_date" style="background-color: #fff;border: 1px solid #ccc;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;width:217px;color:#555;transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">&nbsp;-
									<input id="end_o_date" name="end_o_date" style="background-color: #fff;border: 1px solid #ccc;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;width:217px;color:#555;transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
								</div>
							</div>
							<div class="form-actions">
								<input id="btn_search" type="button" class="btn btn-success" value="搜索">
								<button id="btn_preview" type="button" class="btn btn-primary">发票预览</button>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	
	<div class="row-fluid">
      <div class="span12">
        <div class="widget-box">
          <div class="widget-title"> <span class="icon"> <i class="icon-th"></i> </span>
            <h5>搜索结果</h5>
          </div>
          <div class="widget-content nopadding">
            <table id="search_result"  class="table table-bordered table-striped">
              <thead>
					<tr>
					  <th><input type="checkbox" id="page_inv_cbx_all"/></th>
					  <th>订单/明细编号</th>
					  <th>产品</th>
					  <th>经销商姓名</th>
					  <th>经销商类型</th>
	                  <th>发货时间</th>
	                  <th>订单时间</th>
	                  <th>数量</th>
	                  <th>单价</th>
	                  <th>总价</th>
	                  <th>税号</th>
	                  <th>开户行账号</th>
	                  <th>地址,电话</th>
					</tr>
				</thead>
              <tbody>
              </tbody>
            </table>
          </div>
      </div>
     </div>
		 <div id="paging" class="fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix">
        	<div class="dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi ui-buttonset-multi paging_full_numbers" id="DataTables_Table_0_paginate">
        		 <!-- <span>共<span id="total_count">0</span>条 <span id="curr_page_index">0</span>/<span id="total_page">0</span></span>&nbsp; -->
        		 <span><span id="curr_size">0</span>/<span id="total_count">0</span></span>&nbsp;&nbsp;&nbsp;
       			<a class="next fg-button ui-button ui-state-default ui-state-disabled" tabindex="0" id="DataTables_Table_0_next">加载更多</a>
       		</div>
    	</div>
    </div>
  </div>

</div>
</block>

<block name="js_content">
<script src="../../../Public/js/laydate/laydate.js"></script>
<script src="/Public/js/layer/layer.js" type="text/javascript"></script>
<script >
	PaperInvListPage = {
			'BindEvent': function(){
				$('#btn_search').bind('click', function(){
					var page_index = 1;
					PaperInvListPage.Search(page_index);
				});
				$('#btn_preview').bind('click',function(){
					var check_itms = $("input:checkbox[name='page_inv_cbx']:checked");
					if(check_itms.size() > 0){
						var oids = new Array();
						var dealerType = $('#search_result').data($(check_itms[0]).attr('id')).dealer_type;
						$.each(check_itms, function(index, obj){
						  	var itm = $('#search_result').data($(obj).attr('id'));
						  	if(itm.dealer_type != dealerType){
						  		layer.msg('所选数据的经销商类型不同,不能继续操作', {icon: 5});
						  		oids = null;
						  		return false;
						  	}
						  	oids.push(itm.oid);
						});
						if(oids != null){
							if(oids.length > 0 &&  oids.length <= 100){
								window.open('/Dealer/paperInvPreview?'+ 'oids=' + oids);
							}else if(oids.length > 100){
								layer.msg('单次操作,勾选项最多100条', {icon: 5});
							}
							return;
						}
					}else{
						layer.msg('没有勾选项,无法进行发票预览', {icon: 5});
					}
				});
				$(".first,.previous,.last,.next").bind('click', function(){
					if($(this).hasClass('ui-state-disabled')){
						return false;
					}
					var page_index = $(this).attr('page_index');
					if(page_index == undefined){
						page_index = 1;
					}
					PaperInvListPage.Search(page_index);
				});
			},
			'Search': function(page_index){
				var start_date	= $('#start_date').val();
				var end_date	= $('#end_date').val();
				if(end_date !=""){
					if(start_date ==""){
						alert("发货开始日期不能为空！！！");
						return ;
					}
				}
				if(start_date !=""){
					if(end_date ==""){
						alert("发货结束日期不能为空！！！");
						return ;
					}
				}
				var start_o_date	= $('#start_o_date').val();
				var end_o_date	= $('#end_o_date').val();
				if(end_o_date !=""){
					if(start_o_date ==""){
						alert("订单开始日期不能为空！！！");
						return ;
					}
				}
				if(start_o_date !=""){
					if(end_o_date ==""){
						alert("订单结束日期不能为空！！！");
						return ;
					}
				}
				var page_size = 10;
			  	var condition = $("#basic_validate").serialize() + ("&pageSize="+ page_size +"&index=" + page_index);
			  	$.ajax({
					type : 'post',
					url : '/AjaxService/center/order/searchpaperinvlist',
					data : condition,
					dataType : 'json',
					async : true,
					success : function(data) {
						if(data.IsSuccess == 0){
							layer.msg(data.ErrorMsg, {icon: 5});
						}else{
							var total_page = data.Result.total_page;
							var total_count = data.Result.total_count;
							var order_info_en = data.Result.lst_order_info_en;
							PaperInvListPage.FillTable(order_info_en, page_index , total_page);
							PaperInvListPage.SetPageIndex(order_info_en.length, page_size,total_page, total_count, page_index);
						}
					},
					error : function(e, err_name, err_text) {
						layer.msg(err_text, {icon: 5});
					}
				});
			},
			'FillTable': function(lst_order_info_en, page_index, total_page){
				if(page_index == 1){ //第一页需要清空信息
					$('#search_result tbody').html('');
				}
				var html_array = new Array();
				if(lst_order_info_en.length > 0){
					for(var index in lst_order_info_en){
						var order_info_en = lst_order_info_en[index];
						html_array.push('<tr class="odd gradeX">');
						html_array.push('<td style="text-align:center"><input type="checkbox" name="page_inv_cbx" id="'+order_info_en.oid+'"/></td>');
						html_array.push('<td>' + order_info_en.order_id + '<br/><span style="color:#F75000">' + order_info_en.oid + '</span></td>');
						/* html_array.push('<td>' + order_info_en.oid + '</td>'); */
						html_array.push('<td>' + order_info_en.sku_name + '</td>');
						html_array.push('<td>' + order_info_en.dealer_name + '</td>');
						html_array.push('<td>' + order_info_en.dealer_type_text + '</td>');
						html_array.push('<td>' + CommonPage.convertNull(order_info_en.send_date) + '</td>');
						html_array.push('<td>' + CommonPage.convertNull(order_info_en.order_date) + '</td>');
						html_array.push('<td>' + order_info_en.qty + '</td>');
						html_array.push('<td>' + (order_info_en.sale_amount/order_info_en.qty).toFixed(2) + '</td>');
						html_array.push('<td>' + order_info_en.sale_amount + '</td>');
						html_array.push('<td>' + order_info_en.tax_no + '</td>');
						html_array.push('<td>' + order_info_en.bank_no + '</td>');
						var str_tmp = '';
						if((order_info_en.registered_address != null && order_info_en.registered_address != '')  && 
								(order_info_en.finance_leader_cellphone != null && order_info_en.finance_leader_cellphone != '')){
							str_tmp = order_info_en.registered_address + ',' + order_info_en.finance_leader_cellphone;
						}else if(order_info_en.registered_address != null && order_info_en.registered_address != '' ){
							str_tmp = order_info_en.registered_address;
						}else if(order_info_en.finance_leader_cellphone != null && order_info_en.finance_leader_cellphone != ''){
							str_tmp = order_info_en.finance_leader_cellphone;
						}
						html_array.push('<td>' + str_tmp + '</td>');
						html_array.push('</tr>');
						//缓存数据
						$('#search_result').data(order_info_en.oid,order_info_en);
					}
				}else if(page_index == 1){ //只有第一页需要显示该信息
					html_array.push('<td style="text-align:center" colspan="16">没查到数据</td>');
				}
				
				var html = html_array.join('\r\n');
				$('#search_result tbody').append(html);
				$('#search_result').attr('page_index', page_index);
				$("input:checkbox[name='page_inv_cbx']").each(function(i, obj){
					if($(obj).parent().parent().hasClass('checker') == false){
						$(obj).uniform();
					}
				 });
			},
			'SetPageIndex': function(curr_count, page_size,total_page, total_count, page_index){
				$('#total_count').text(total_count);
				if(curr_count == null){
					curr_count = 0;
				}
				var exist_size =  ((page_index > 0)?((page_index-1) * page_size) : 0) + curr_count;
				$('#curr_size').text(exist_size);
				page_index = parseInt(page_index);
				total_count = parseInt(total_count);
				if(total_page == page_index || total_page == 0){
					$('#paging .next').addClass('ui-state-disabled');
					$('#paging .next').attr('page_index', total_page);
				}else{
					$('#paging .next').removeClass('ui-state-disabled');
					$('#paging .next').attr('page_index', page_index + 1);
				}
		 },
	};
	$(document).ready(function(){
		PaperInvListPage.BindEvent();
	});
</script>
</block>